<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:70:"E:\WWW\waimai/app/admin/wechat\view\wechat_template_message\index.html";i:1502520857;s:53:"E:\WWW\waimai/app/admin/index\view\template\base.html";i:1495522842;}*/ ?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="__STATIC__/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <!--图标字体元件库-->
    <link rel="stylesheet" href="__STATIC__/plugins/font-awesome4.5.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="__STATIC__/admin/css/AdminLTE.min.css">
    <link rel="stylesheet" href="__STATIC__/admin/css/jquery.datetimepicker.css">
    <link rel="stylesheet" href="__STATIC__/admin/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="__STATIC__/plugins/validform/5.3.2/css/Validateform_v5.3.2.css">

    <link rel="stylesheet" href="__STATIC__/plugins/bootstrap-table/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/polaris/polaris.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/futurico/futurico.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/line/_all.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/square/_all.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/flat/_all.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/minimal/_all.css">
    



    <title><?php echo \think\Config::get('site.title'); ?></title>
    

    <script src="__STATIC__/plugins/jquery/jquery-3.0.0.min.js"></script>
    <script src="__STATIC__/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="__STATIC__/admin/js/app.min.js"></script>
    <script src="__STATIC__/admin/extend/app.js"></script>

    <script src="__STATIC__/admin/extend/H-ui.admin.js"></script>
    <script src="__STATIC__/plugins/layer3.0.3/layer.js"></script>
    <script src="__STATIC__/plugins/validform/5.3.2/Validform_v5.3.2_min.js"></script>

    <script src="__STATIC__/plugins/bootstrap-table/bootstrap-table.min.js" type="text/javascript"></script>
    <script src="__STATIC__/plugins/bootstrap-table/bootstrap-table-zh-CN.js" type="text/javascript"></script>

    <script src="__STATIC__/plugins/iCheck/icheck.min.js"></script>
    <script>

        var admin_menu_data=<?php if(isset($admin_menu)): ?><?php echo $admin_menu; endif; ?>;
        $(function () {
            $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
                checkboxClass: 'icheckbox_minimal-blue',
                radioClass: 'iradio_minimal-blue'
            });
        })
    </script>

    


</head>
<body class="hold-transition skin-blue-light sidebar-mini">
    
<div class="row">
    <div class="col-xs-12">
        <div class="box box-primary">
            <div class="box-body">
                <div id="toolbar">
                    <div class="btn-group pull-left mr10">
                        <a class="btn btn-primary" id="add_btn"><i class="fa fa-plus"></i> 新增</a>
                    </div>
                </div>
                <table id="table"
                       data-toggle="table"
                       data-show-refresh="true"
                       data-side-pagination="server"
                       data-pagination="true"
                       data-url="<?php echo url('wechat/WechatTemplateMessage/index_data'); ?>"
                >
                    <thead>
                    <tr>
                        <th data-field="id">编号</th>
                        <th data-field="title">模板标题</th>
                        <th data-field="template_short_id">模板编号</th>
                        <th data-field="template_id">模板ID</th>
                        <th data-field="status" data-formatter="formatStatus">是否启用</th>
                        <th data-field="operate" data-formatter="formatOperate" data-events="operateEvents" >操作</th>
                    </tr>
                    </thead>
                </table>
            </div><!-- /.box-body -->
        </div><!-- /.box -->
    </div><!-- /.col -->
</div><!-- /.row -->


</body>
<script src="__STATIC__/admin/js/skins_control.js"></script>
<script src="__STATIC__/admin/js/jquery.datetimepicker.js"></script>

<script>
    var table=$('#table');
    var add_data_url="<?php echo url('wechat/wechatTemplateMessage/add'); ?>";
    var edit_data_url="<?php echo url('wechat/wechatTemplateMessage/edit'); ?>";
    var delete_data_url="<?php echo url('wechat/wechatTemplateMessage/delete'); ?>";
</script>
<script>
    //格式化掉 末尾 .html
    function urlFormat(url) {
        if (url.indexOf('.html'))
        {
            url = url.replace('.html', '');
        }
        return url;
    }
    // <editor-fold defaultstate="collapsed" desc="添加">
    $('#add_btn').on('click',function(){
        layer_open('新增模板消息',add_data_url)
    });
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="操作">
    function formatOperate(value, row, index) {
        return [
            '<button class="btn btn-warning btn-sm row_edit" href="javascript:void(0)">',
            '修改',
            '</button>&nbsp;',
            '<button class="btn btn-danger btn-sm row_delete" href="javascript:void(0)">',
            ' 删除',
            '</button>'
        ].join('');
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="操作函数">
    window.operateEvents = {
        'click .row_edit': function (e, value, row, index) {
            layer_open('编辑',urlFormat(edit_data_url)+"/id/"+row.id);
        },
        'click .row_delete': function (e, value, row, index) {
            layer.confirm('你确定要删除该选项吗？', {btn: ['确定', '取消']}, function () {
                $.ajax({
                    dataType: 'json',
                    data: {id: row.id},
                    url: delete_data_url,
                    success: function (res) {
                        if (res.success) {
                            layer.msg(res.message);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.alert(res.message, {icon: 5})
                        }
                    }
                })
            })
        }
    };
    function formatStatus(value,row,index){
        if(value==1){
            return '<button onclick="changeStatus('+index+','+row.id+','+row.status+')" class="btn btn-success btn-xs" href="javascript:void(0)"><i class="fa fa-check-circle"></i> 启用</button>'
        }else{
            return '<button onclick="changeStatus('+index+','+row.id+','+row.status+')" class="btn btn-warning btn-xs" href="javascript:void(0)"><i class="fa fa-circle-o"></i> 禁用</button>'
        }
    }

    function changeStatus(index,id,status){
        var data={};
        if(status==1){
            data={id:id,status:0};
            $.ajax({
                dataType:'json',
                data:data,
                url:"<?php echo url('wechat/WechatTemplateMessage/changeStatus'); ?>",
                success:function(res){
                    table.bootstrapTable('updateRow',{index:index,row:{status:0}});
                }
            })
        }else{
            data={id:id,status:1}
            $.ajax({
                dataType:'json',
                data:data,
                url:"<?php echo url('wechat/WechatTemplateMessage/changeStatus'); ?>",
                success:function(res){
                    table.bootstrapTable('updateRow',{index:index,row:{status:1}});
                }
            })
        }

    }
</script>

</html>